package org.ichihamigua.video.controller;

import jakarta.annotation.Resource;
import org.ichihamigua.common.framework.entity.Result;
import org.ichihamigua.common.qiniucloud.service.QiniuObjectStoreService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author rainkyzhong
 * @date 2023/11/4 13:55
 */
@RequestMapping("/upload")
@RestController
public class UploadController {

    @Resource
    private QiniuObjectStoreService qiniuObjectStoreService;

    @PostMapping("/init")
    public Result<?> init(){
        return qiniuObjectStoreService.initiateMultipartUpload("ichihamigua", "1.mp4");
    }

    @PostMapping("/push")
    public Result<?> push(String uploadId, Integer partNumber, MultipartFile file){
        return qiniuObjectStoreService.uploadPart("ichihamigua","1.mp4",uploadId, partNumber,file);
    }

    @PostMapping("/finish")
    public Result<?> finish(String uploadId){
        return qiniuObjectStoreService.completeMultipartUpload("ichihamigua","1.mp4",uploadId);
    }

}
